import * as echarts from 'echarts'

// let xLabel = ['3.26', '3.27', '3.28', '3.29', '3.30', '3.31']

const option = {
    // backgroundColor: '#0e1c47',
    tooltip: {
        trigger: 'axis',
        backgroundColor: 'transparent',
        axisPointer: {
            lineStyle: {
                color: {
                    type: 'linear',
                    x: 0,
                    y: 0,
                    x2: 0,
                    y2: 1,
                    colorStops: [{
                        offset: 0,
                        color: 'rgba(126,199,255,0)' // 0% 处的颜色
                    }, {
                        offset: 0.5,
                        color: 'rgba(126,199,255,1)' // 100% 处的颜色
                    }, {
                        offset: 1,
                        color: 'rgba(126,199,255,0)' // 100% 处的颜色
                    }],
                    global: false // 缺省为 false
                }
            },
        },
        formatter: (p) => {
            let dom = `<div style="width: 140px;
                height: 160px;padding:5px;color:#fff;position: relative;">
                      <svg style="position: absolute;top: 50%;
                  left: 50%;
                  transform: translateX(-50%) translateY(-50%);" class="svg" xmlns="http://www.w3.org/2000/svg" width="140" height="160" viewBox="0 0 80 90">
                    <defs>
                      <style>
                        .cls-1 {
                          fill: #07172c;
                          fill-opacity: 0.7;
                          stroke: #a7d8ff;
                          stroke-linejoin: round;
                          stroke-opacity: 0.2;
                          stroke-width: 1px;
                          fill-rule: evenodd;
                        }

                      </style>
                    </defs>
                    <path id="矩形_419" data-name="矩形 419" class="cls-1" d="M266,595h74v50H266V624.046L261,620l5-3.984V595Z"
                      transform="translate(-258.5 -592.5)" />
                  </svg>
                      <div style="padding: 4px 8px 4px 12px;display: flex;
                      justify-content: center;
                      align-items: center;
                      flex-direction: column;position: relative;z-index: 1;">
                          <div style="width:90%;display:${p[0] ? 'flex' : 'none'};justify-content:space-between;align-items:center;">
                              <span style="font-size:13px;color:#7ec7ff;">${p[0] ? p[0].seriesName : ''}</span>
                              <span style="font-size:13px;color:#fff;">${p[0] ? p[0].data : ''}</span>
                          </div>
                          <div style="width:90%;height:100%;display:${p[1] ? 'flex' : 'none'};justify-content:space-between;align-items:center;">
                              <span style="font-size:13px;color:#7ec7ff;">${p[1] ? p[1].seriesName : ''}</span>
                              <span style="font-size:13px;color:#fff;">${p[1] ? p[1].data : ''}</span>
                          </div>
                          <div style="width:90%;height:100%;display:${p[2] ? 'flex' : 'none'};justify-content:space-between;align-items:center;">
                              <span style="font-size:13px;color:#7ec7ff;">${p[2] ? p[2].seriesName : ''}</span>
                              <span style="font-size:13px;color:#fff;">${p[2] ? p[2].data : ''}</span>
                          </div>
                           <div style="width:90%;height:100%;display:${p[3] ? 'flex' : 'none'};justify-content:space-between;align-items:center;">
                              <span style="font-size:13px;color:#7ec7ff;">${p[3] ? p[3].seriesName : ''}</span>
                              <span style="font-size:13px;color:#fff;">${p[3] ? p[3].data : ''}万</span>
                          </div>
                      </div>
                  </div>`
            return dom
        }
    },
    legend: {
        align: "left",
        left: '20%',
        top: '0%',
        type: 'plain',
        textStyle: {
            color: '#7ec7ff',
            fontSize: 12
        },
        // icon:'rect',
        itemGap: 6,
        itemWidth: 30,
        icon: 'path://M0 2a2 2 0 0 1 2 -2h14a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2z',

        data: [
            {
                name: '事故数'
            },
            {
                name: '受伤人数'
            },
            {
                name: '死亡人数'
            },
            {
                name: '财产损失'
            }
        ]
    },
    grid: {
        top: '25%',
        left: '12%',
        right: '15%',
        bottom: '15%',
        // containLabel: true
    },
    xAxis: [{
        type: 'category',
        boundaryGap: false,
        axisLine: { //坐标轴轴线相关设置。数学上的x轴
            show: true,
            lineStyle: {
                color: '#233653'
            },
        },
        axisLabel: { //坐标轴刻度标签的相关设置
            textStyle: {
                color: '#7ec7ff',
                // padding: 16,
                fontSize: 12
            },
            formatter: function (data) {
                return data
            }
        },
        splitLine: {
            show: false,
            lineStyle: {
                // color: '#192a44'
                // color: "rgba(201, 205, 254, 0.2)"
                color: 'rgba(201, 205, 254, 1)'
            },
        },
        axisTick: {
            show: false,
        },
        data: []
    }],
    yAxis: [{
        name: '数量',
        nameTextStyle: {
            color: "#aaa",
            fontSize: 12,
            fontWeight: 700
        },
        min: 0,
        splitLine: {
            show: true,
            lineStyle: {
                // color: '#192a44'
                color: "rgba(201, 205, 254, 0.2)"
            },
        },
        axisLine: {
            show: true,
            lineStyle: {
                color: "rgba(201, 205, 254, 0.2)"
            }

        },
        axisLabel: {
            show: true,
            textStyle: {
                // color: '#7ec7ff',
                color: 'rgba(201, 205, 254, 1)',
                padding: 6
            },
            formatter: function (value) {
                if (value === 0) {
                    return value
                }
                return value
            }
        },
        axisTick: {
            show: false,
        },
    },
    {
        name: '万元',
        nameTextStyle: {
            color: "#aaa",
            fontSize: 12,
            fontWeight: 700
        },
        min: 0,
        splitLine: {
            show: false,
            lineStyle: {
                color: "rgba(201, 205, 254, 0.2)"
            },
        },
        axisLine: {
            show: true,
            lineStyle: {
                color: "rgba(201, 205, 254, 0.2)"
            }

        },
        axisLabel: {
            show: true,
            textStyle: {
                // color: '#7ec7ff',
                color: 'rgba(201, 205, 254, 1)',
                padding: 6
            },
            formatter: function (value) {
                if (value === 0) {
                    return value
                }
                return value
            }
        },
        axisTick: {
            show: false,
        },
    }],
    series: [
        {
            name: '事故数',
            type: 'line',
            symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
            showAllSymbol: true,
            symbolSize: 0,
            smooth: true,
            lineStyle: {
                normal: {
                    width: 5,
                    color: "rgba(25,163,223,1)", // 线条颜色
                },
                borderColor: 'rgba(0,0,0,.4)',
            },
            itemStyle: {
                color: "rgba(25,163,223,1)",
                borderColor: "#646ace",
                borderWidth: 2

            },
            tooltip: {
                show: true
            },
            areaStyle: { //区域填充样式
                normal: {
                    //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: "rgba(25,163,223,.3)"
                    },
                    {
                        offset: 1,
                        color: "rgba(25,163,223, 0)"
                    }
                    ], false),
                    shadowColor: 'rgba(25,163,223, 0.5)', //阴影颜色
                    shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
                }
            },
            data: []
        },
        {
            name: '受伤人数',
            type: 'line',
            symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
            showAllSymbol: true,
            symbolSize: 0,
            smooth: true,
            lineStyle: {
                normal: {
                    width: 5,
                    color: "rgba(10,219,250,1)", // 线条颜色
                },
                borderColor: 'rgba(0,0,0,.4)',
            },
            itemStyle: {
                color: "rgba(10,219,250,1)",
                borderColor: "#646ace",
                borderWidth: 2

            },
            tooltip: {
                show: true
            },
            areaStyle: { //区域填充样式
                normal: {
                    //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: "rgba(10,219,250,.3)"
                    },
                    {
                        offset: 1,
                        color: "rgba(10,219,250, 0)"
                    }
                    ], false),
                    shadowColor: 'rgba(10,219,250, 0.5)', //阴影颜色
                    shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
                }
            },
            data: []
        },
        {
            name: '死亡人数',
            type: 'line',
            symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
            showAllSymbol: true,
            symbolSize: 0,
            smooth: true,
            lineStyle: {
                normal: {
                    width: 5,
                    color: "rgba(236,171,68,1)", // 线条颜色
                },
                borderColor: 'rgba(0,0,0,.4)',
            },
            itemStyle: {
                color: "rgba(236,171,68,1)",
                borderColor: "#646ace",
                borderWidth: 2

            },
            tooltip: {
                show: true
            },
            areaStyle: { //区域填充样式
                normal: {
                    //线性渐变，前4个参数分别是x0,y0,x2,y2(范围0~1);相当于图形包围盒中的百分比。如果最后一个参数是‘true’，则该四个值是绝对像素位置。
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: "rgba(236,171,68,0.3)"
                    },
                    {
                        offset: 1,
                        color: "rgba(236,171,68,0)"
                    }
                    ], false),
                    shadowColor: 'rgba(236,171,68,0.5)', //阴影颜色
                    shadowBlur: 20 //shadowBlur设图形阴影的模糊大小。配合shadowColor,shadowOffsetX/Y, 设置图形的阴影效果。
                }
            },
            data: []
        },
        {
            name: '财产损失',
            type: 'bar',
            yAxisIndex: 1,
            barWidth: 15,
            symbol: 'circle', // 默认是空心圆（中间是白色的），改成实心圆
            showAllSymbol: true,
            symbolSize: 0,
            smooth: true,
            lineStyle: {
                normal: {
                    width: 5,
                    color: "rgba(255,100,97,1)", // 线条颜色
                },
                // borderColor: 'rgba(0,0,0,.4)',
            },

            itemStyle: {
                normal: {
                    barBorderRadius: [15, 15, 0, 0],
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                        offset: 0,
                        color: "rgba(255,100,97,1)"
                    },
                    {
                        offset: 1,
                        color: "rgba(255,100,97,0.3)"
                    }
                    ])
                }
            },
            tooltip: {
                show: true
            },
            data: []
        }
    ]
};


export default ({ xLabel, accidentCounts, injuryCounts, deathCounts, lossCounts }) => {
    option.xAxis[0].data = xLabel
    option.series[0].data = accidentCounts
    option.series[1].data = injuryCounts
    option.series[2].data = deathCounts
    option.series[3].data = lossCounts
    return { ...option }
}